package com.eqdd.yiqidian.ui.gongneng.renshi.yuangongdangan;

import android.databinding.DataBindingUtil;
import android.support.v7.widget.LinearLayoutManager;
import android.text.TextUtils;
import android.view.View;

import com.eqdd.yiqidian.EnterComCheckInfoActivityCustom;
import com.eqdd.yiqidian.R;
import com.eqdd.yiqidian.adapter.slimadapter.SlimAdapterEx;
import com.eqdd.yiqidian.adapter.slimadapter.SlimInjector;
import com.eqdd.yiqidian.adapter.slimadapter.viewinjector.IViewInjector;
import com.eqdd.yiqidian.base.BaseActivity;
import com.eqdd.yiqidian.base.Config;
import com.eqdd.yiqidian.bean.rebuild.ComCheckListResultBean;
import com.eqdd.yiqidian.bean.rebuild.slimedit.SlimEditHintBean;
import com.eqdd.yiqidian.http.DialogCallBack;
import com.eqdd.yiqidian.http.HttpConfig;
import com.eqdd.yiqidian.http.HttpResult;
import com.eqdd.yiqidian.utils.ImageUtil;
import com.eqdd.yiqidian.utils.PicUtil;
import com.eqdd.yiqidian.utils.ToastUtil;

import com.luck.picture.lib.entity.LocalMedia;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;

import java.util.ArrayList;

public class EnterComCheckInfoActivity extends BaseActivity {
    private EnterComCheckInfoActivityCustom dataBinding;
    private LinearLayoutManager mLinearLayoutManager;
    private ArrayList<SlimEditHintBean> datas;
    private ComCheckListResultBean comCheckListResultBean;
    private SlimAdapterEx slimAdapterEx;
    private ArrayList<LocalMedia> localMedias;

    @Override
    public void initBinding() {
        dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_enter_com_check_info);
        initTopTitleBar(View.VISIBLE, "标题");
    }

    @Override
    public void initData() {
        datas = new ArrayList<>();
        comCheckListResultBean = (ComCheckListResultBean) getIntent().getSerializableExtra("ComCheckListResultBean");
        mLinearLayoutManager = new LinearLayoutManager(this);
        dataBinding.recyclerView.setLayoutManager(mLinearLayoutManager);
        dataBinding.recyclerView.setFocusable(false);
        slimAdapterEx = SlimAdapterEx.create().register(R.layout.list_item_28, new SlimInjector<SlimEditHintBean>() {
            @Override
            public void onInject(SlimEditHintBean data, IViewInjector injector) {
                injector.text(R.id.tv_left_content, dealText(data.getTitle()))
                        .text(R.id.tv_right_hint_content, dealText(data.getContent()));
            }
        }).attachTo(dataBinding.recyclerView);
        ImageUtil.setImage(comCheckListResultBean.getUidumfrontphoto(), dataBinding.iv1);
        ImageUtil.setImage(comCheckListResultBean.getUidumbackphoto(), dataBinding.iv2);
        ImageUtil.setImage(comCheckListResultBean.getUwithidumphoto(), dataBinding.iv3);
        ImageUtil.setImage(comCheckListResultBean.getUiphoto(), dataBinding.iv4);
        localMedias = new ArrayList<>();
        localMedias.add(PicUtil.localMedia(comCheckListResultBean.getUidumfrontphoto()));
        localMedias.add(PicUtil.localMedia(comCheckListResultBean.getUidumbackphoto()));
        localMedias.add(PicUtil.localMedia(comCheckListResultBean.getUwithidumphoto()));
        localMedias.add(PicUtil.localMedia(comCheckListResultBean.getUiphoto()));


    }

    @Override
    public void setView() {
        datas.add(new SlimEditHintBean("入职部门", comCheckListResultBean.getDepartName(), 0));
        datas.add(new SlimEditHintBean("入职岗位", comCheckListResultBean.getPostName(), 1));
        datas.add(new SlimEditHintBean("公司名称", comCheckListResultBean.getCompanyName(), 2));
        datas.add(new SlimEditHintBean("手机号", comCheckListResultBean.getUserPhone(), 3));
        datas.add(new SlimEditHintBean("姓名", comCheckListResultBean.getUname(), 4));
        datas.add(new SlimEditHintBean("身份证号", comCheckListResultBean.getUidnum(), 5));
        datas.add(new SlimEditHintBean("户口类型", comCheckListResultBean.getUhousetype(), 6));
        datas.add(new SlimEditHintBean("户籍地址", comCheckListResultBean.getUhouseadress(), 7));
        datas.add(new SlimEditHintBean("性别", comCheckListResultBean.getUsex() == 0 ? "女" : "男", 8));
        datas.add(new SlimEditHintBean("民族", comCheckListResultBean.getUnation(), 9));
        datas.add(new SlimEditHintBean("出生日期", comCheckListResultBean.getUdate(), 10));
        datas.add(new SlimEditHintBean("婚姻状况", comCheckListResultBean.getUmarry(), 11));
        datas.add(new SlimEditHintBean("政治面貌", comCheckListResultBean.getUpoliticstate(), 12));
        datas.add(new SlimEditHintBean("学历", comCheckListResultBean.getUedu(), 13));
        datas.add(new SlimEditHintBean("职业资格", comCheckListResultBean.getUmajor(), 14));
        slimAdapterEx.updateData(datas);

    }

    private String dealText(String text) {
        return TextUtils.isEmpty(text) ? "" : text;
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.bt_reject:
                OkGo.<HttpResult>post(HttpConfig.BASE_URL + HttpConfig.REJECT_PERSON_ENTER_COM)
                        .params("userGuid", user.getGuid())
                        .params("entryId", comCheckListResultBean.getEntryId())
                        .params("userPhone", comCheckListResultBean.getUserPhone())
                        .execute(new DialogCallBack<HttpResult>(this) {
                            @Override
                            public void onSuccess(Response<HttpResult> response) {
                                HttpResult httpResult = response.body();
                                ToastUtil.showShort(httpResult.getMsg());
                                if (httpResult.getStatus() == 200) {
                                    setResult(Config.CHANGE);
                                    finish();
                                }
                            }
                        });
                break;
            case R.id.bt_accept:
                OkGo.<HttpResult>post(HttpConfig.BASE_URL + HttpConfig.AGREE_PERSON_ENTER_COM)
                        .params("userGuid", user.getGuid())
                        .params("entryId", comCheckListResultBean.getEntryId())
                        .params("userPhone", comCheckListResultBean.getUserPhone())
                        .execute(new DialogCallBack<HttpResult>(this) {
                            @Override
                            public void onSuccess(Response<HttpResult> response) {
                                HttpResult httpResult = response.body();
                                ToastUtil.showShort(httpResult.getMsg());
                                if (httpResult.getStatus() == 200) {
                                    setResult(Config.CHANGE);
                                    finish();
                                }
                            }
                        });
                break;
            case R.id.iv_1:
                PicUtil.preview(this, 0, localMedias);
                break;
            case R.id.iv_2:
                PicUtil.preview(this, 1, localMedias);

                break;
            case R.id.iv_3:
                PicUtil.preview(this, 2, localMedias);

                break;
            case R.id.iv_4:
                PicUtil.preview(this, 3, localMedias);

                break;

        }
    }
}
